<?php
$rsFacturas = $this->lastResult;

if(!isEmpty(getParam("carnet"))){
    $value = getParam("carnet");
    $pieces = explode(" - ", $value);
    $carnet = $pieces[0];
}

$when = isEmpty(getParam("desde")) && isEmpty(getParam("hasta")) ? " hasta el día de hoy": " del ".getParam("desde")." al ".getParam("hasta");
$who = isEmpty(getParam('carnet')) ? "" : " del alumno(a) ". $this->stud;
?>
<div style="width:100%; overflow:auto;">
    <input type="hidden" name="page" id="page" />

                <table style="font-size:8px;border-collapse: collapse;width:100%" class="table table-bordered table-striped" width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th colspan="23"><legend>Facturas Generadas<?php echo $when . $who; ?></legend></th>
                    </tr>
                    <tr>
                        <th style="padding-right:0px;padding-left: 0px">Factura Serie A</th>
                        <th style="padding-right:0px;padding-left: 0px">Fecha</th>
                        <th style="padding-right:0px;padding-left: 0px">Nombre</th>
                        <th style="padding-right:0px;padding-left: 0px">ID Estudiante</th>
                        <th style="padding-right:0px;padding-left: 0px">Efectivo Q.</th>
                        <th style="padding-right:0px;padding-left: 0px">Cheque BI</th>
                        <th style="padding-right:0px;padding-left: 0px">Cheque Otros Bancos</th>
                        <th style="padding-right:0px;padding-left: 0px">Deposito Directo</th>
                        <th style="padding-right:0px;padding-left: 0px"># Boleta</th>
                        <th style="padding-right:0px;padding-left: 0px">Dolares</th>
                        <th style="padding-right:0px;padding-left: 0px">Inscripciones</th>
                        <th style="padding-right:0px;padding-left: 0px">Mes Ant.</th>
                        <th style="padding-right:0px;padding-left: 0px">Mes Act.</th>
                        <th style="padding-right:0px;padding-left: 0px">Mes Sig.</th>
                        <th style="padding-right:0px;padding-left: 0px">Mora</th>
                        <th style="padding-right:0px;padding-left: 0px">Libros</th>
                        <th style="padding-right:0px;padding-left: 0px">Diplomados Externos</th>
                        <th style="padding-right:0px;padding-left: 0px">Otros</th>
                        <th style="padding-right:0px;padding-left: 0px">Cargos Cheques Rech.</th>
                        <th style="padding-right:0px;padding-left: 0px">Nombre Bancos</th>
                        <th style="padding-right:0px;padding-left: 0px">No. de cheque</th>
                        <th style="padding-right:0px;padding-left: 0px">Total Distribución</th>
                        <th style="padding-right:0px;padding-left: 0px"><strong>Tasa Cambio</strong></th>
                    </tr>
                    <?php
                    
                    
                    #if(!$this->noData($rsFacturas)){
                    #    return false;
                    #};
                    //TOTALES RESUMEN GENERAL
                    $union = isEmpty(getParam("carnet")) ? NULL : "SELECT AVG(TASA_CAMBIO) AS PROMEDIO FROM cllg_factura WHERE FK_STUDENT=$carnet AND STATUS!=0";
                    
                    $totalQ = 0;
                    $totalBI = 0;
                    $totalOtrosBancos = 0;
                    $totalTramite = 0;
                    $totalEfectivo = 0;
                    $totalDeposito = 0;
                    $totalDolares = 0;
                    $totalFact = 0;
                    $tipoCambio = $this->getTasaProm("TASA_CAMBIO","cllg_factura",$union);
                
                    //TOTALES RESUMEN TIPO DE PAGO
                    $totalInscripcion = 0;
                    $totalMesAtras = 0;
                    $totalMesActual = 0;
                    $totalMesSiguiente = 0;
                    $totalMora = 0;
                    $totalLibros = 0;
                    $totalDiplo = 0;
                    $totalOtros = 0;
                    $totalChRecha = 0;
                    
                    //CONTADORES
                    $iInscripcion = 0;
                    $iMesAtras = 0;
                    $iMesActual = 0;
                    $iMesSiguiente = 0;
                    $iMora = 0;
                    $iLibros = 0;
                    $iDiplo = 0;
                    $iOtros = 0;
                    $iChRecha = 0;
                    $iBI = 0;
                    $iOtrosBancos = 0;
                    $iEfectivo = 0;
                    $iDeposito = 0;
                    $iDolares = 0;
                    $iFact = 0;
                    
                    foreach ($rsFacturas as $r){
                        
                        $iFact += 1;
                        $inscripcion = 0;
                        $mesAtras = 0;
                        $mesSiguiente = 0;
                        $mesActual = 0;
                        $mora = 0;
                        $libros = 0;
                        $diplo = 0;
                        $otros = 0;
                        $chRecha = 0;
                        
                        
                       
                       
                       if($r['FK_EMPRESA'] == NULL){
                            $motivosStr = $this->db->query_select("cllg_factura_detalle",sprintf("FK_FACTURA=%s", $r['ID']));
                            foreach ($motivosStr as $m){

                            $des = strtolower($m['DESCRIPCION']);                       
                                 if($this->contains($des,"ins") || $this->contains($des,"inscripcion")){
                                         $inscripcion += $m['SUBTOTAL'];
                                         $iInscripcion++;
                                 }else {
                                     if($this->contains($des,"mora")){
                                         $mora += $m['SUBTOTAL'];
                                         $iMora++;
                                     }else {
                                         if($this->contains($des,"libro") || $this->contains($des,"libros") || $this->contains($des,"cartilla") ){
                                             $libros += $m['SUBTOTAL'];
                                             $iLibros++;
                                         }else {
                                             if($this->contains($des,"diplo") || $this->contains($des,"semin") || $this->contains($des,"confe")){
                                                 $diplo += $m['SUBTOTAL'];
                                                 $iDiplo++;
                                             }else {
                                                 if($this->contains($des,"recha")){
                                                     $chRecha += $m['SUBTOTAL'];
                                                     $iChRecha++;
                                                 }else {
                                                     if($this->contains($des,"mensualidad") || $this->contains($des,"cuota") || $this->contains($des,"mens")){

                                                         $sqlDate = "
                                                                 SELECT DATE_LIMIT
                                                                 FROM cllg_cargo
                                                                 WHERE cllg_cargo.ID IN (
                                                                 SELECT FK_CARGO 
                                                                 FROM cllg_mov_cargo 
                                                                 WHERE FK_FACTURA={$r['ID']} AND DESCRIPTION='{$m['DESCRIPCION']}')";

                                                         $date = $this->db->query($sqlDate);



                                                         $d = mysql_fetch_assoc($date);

                                                         $cYear = date("Y",strtotime($r["FECHA"]));
                                                         $cMonth = date("m",strtotime($r["FECHA"]));
                                                         $fYear = date("Y",strtotime($d['DATE_LIMIT']));
                                                         $fMonth = date("m",strtotime($d['DATE_LIMIT']));
                                                         if( intval($cYear) > intval($fYear) ) { //si es de a;o anterior
                                                             $mesAtras += $m['SUBTOTAL'];
                                                             $iMesAtras++;
                                                         }else {
                                                             if(intval($cYear) < intval($fYear)) {
                                                                 $mesSiguiente += $m['SUBTOTAL'];
                                                                 $iMesSiguiente++;
                                                             }else {
                                                                 if(intval($cMonth) == intval($fMonth)) {
                                                                     $mesActual += $m['SUBTOTAL'];
                                                                     $iMesActual++;
                                                                 }else {
                                                                     if(intval($cMonth) < intval($fMonth)) {
                                                                         $mesSiguiente += $m['SUBTOTAL'];
                                                                         $iMesSiguiente++;
                                                                     }else {
                                                                         if(intval($cMonth) > intval($fMonth)){
                                                                             $mesAtras += $m['SUBTOTAL'];
                                                                             $iMesAtras++;
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }else {
                                                         $otros += $m['SUBTOTAL'];
                                                         $totalOtros += $m['SUBTOTAL'];
                                                         $iOtros++;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                            }
                        }else{
                            $motivosStr = $this->db->queryToArray(sprintf(
                                    "SELECT * 
                                     FROM cllg_cargo
                                     WHERE ID IN(
                                        SELECT FK_CARGO
                                        FROM cllg_mov_cargo
                                        WHERE FK_FACTURA='%s')
                                        ", $r['ID']));
                            
                            foreach ($motivosStr as $m){
                                
                            $movCargo = $this->db->query_select("cllg_mov_cargo","FK_FACTURA='{$r['ID']}' AND FK_CARGO='{$m['ID']}'");
                            $amount = $movCargo[0]['MONTO'];
                            $des = strtolower($m['DESCRIPTION']);                       
                                 if($this->contains($des,"ins") || $this->contains($des,"inscripcion")){
                                         $inscripcion += $amount;
                                         $iInscripcion++;
                                 }else {
                                    if($this->contains($des,"mensualidad") || $this->contains($des,"cuota") || $this->contains($des,"mens")){

                                        $cYear = date("Y",strtotime($r["FECHA"]));
                                        $cMonth = date("m",strtotime($r["FECHA"]));
                                        $fYear = date("Y",strtotime($m['DATE_LIMIT']));
                                        $fMonth = date("m",strtotime($m['DATE_LIMIT']));
                                        if( intval($cYear) > intval($fYear) ) { //si es de a;o anterior
                                            $mesAtras += $amount;
                                            $iMesAtras++;
                                        }else {
                                            if(intval($cYear) < intval($fYear)) {
                                                $mesSiguiente += $amount;
                                                $iMesSiguiente++;
                                            }else {
                                                if(intval($cMonth) == intval($fMonth)) {
                                                    $mesActual += $amount;
                                                    $iMesActual++;
                                                }else {
                                                    if(intval($cMonth) < intval($fMonth)) {
                                                        $mesSiguiente += $amount;
                                                        $iMesSiguiente++;
                                                    }else {
                                                        if(intval($cMonth) > intval($fMonth)){
                                                            $mesAtras += $amount;
                                                            $iMesAtras++;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }else {
                                        $otros += $m['AMOUNT'];
                                        $totalOtros += $m['AMOUNT'];
                                        $iOtros++;
                                    }
                                 }
                            }
                        }
                        
                        $dolares = $r['DOLARES'];
                        $stadoFactu = $r['STATUS'];
                    
                        $cheque = $this->db->query(sprintf("SELECT * FROM cllg_cheque WHERE cllg_cheque.FK_FACURA = %s",$r['ID']));
                        $ch = mysql_fetch_assoc($cheque);
                        
                             if ($stadoFactu != 0 && $r['TOTAL'] != 0){
                                 $totalInscripcion += $inscripcion;
                                 $totalMesAtras += $mesAtras;
                                 $totalMesActual += $mesActual;
                                 $totalMesSiguiente += $mesSiguiente;
                                 $totalMora += $mora;
                                 $totalLibros += $libros;
                                 $totalDiplo += $diplo;
                                 $totalChRecha += $chRecha;
                             }
                             
                             if($ch['BANCO'] == "BI"){
                                if($stadoFactu != 0){
                                $totalBI += $r['CHEQUE'];
                                $iBI++;
                                }
                             }
                            if($ch['BANCO'] != "BI"){
                                if ($stadoFactu != 0){
                                $totalOtrosBancos += $r['CHEQUE'];
                                $iOtrosBancos++;
                                }
                            }
                            if($stadoFactu != 0){
                                if($stadoFactu == 1 || $stadoFactu == NULL){
                                    $totalQ += $r['TOTAL'];
                                }
                                else{
                                    $totalTramite += $r['TOTAL'];
                                }
                            }
                            $totalEfectivo += $stadoFactu == 0 ? 0 : ($r['EFECTIVO'] == NULL ? 0 : $r["EFECTIVO"] + $r["TARJETA"]);
                            $totalDeposito += $stadoFactu == 0 ? 0 : ($r['DEPOSITO'] == NULL ? 0 : $r["DEPOSITO"]);
                            $totalDolares += $stadoFactu == 0 ? 0 : ($r['DOLARES'] == NULL ? 0 : $r["DOLARES"]);
                            $totalFact += $stadoFactu == 0 ? 0 : ($r['TOTAL'] == NULL ? 0 : $r["TOTAL"]);
                            
                            $iEfectivo += $stadoFactu == 0 ? 0 : (intval($r['EFECTIVO']) > 0 ? 1 : 0);
                            $iDeposito += $stadoFactu == 0 ? 0 : (intval($r['DEPOSITO']) > 0 ? 1 : 0);
                            $iDolares += $stadoFactu == 0 ? 0 : (intval($r['DOLARES']) > 0 ? 1 : 0);
                    ?>
                        <tr>
                            <td ><?php echo $r['NUMERO'];?></td>
                            <td><?php print date("d-m",strtotime($r['FECHA'])); ?></td>
                            <td><?= $stadoFactu == 0 ? '<span style="color:red">ANULADA</span>' : ( $stadoFactu == 1 ? $r['NOMBRE'] : '<span style="color:blue">EN TRAMITE</span>' ); ?></td>
                            <td><?= $stadoFactu == 0 ? '<span style="color:red">ANULADA</span>' : ( $stadoFactu == 1 ? ($r['FK_STUDENT'] == NULL ? "&nbsp;" : $r['FK_STUDENT'] ) : '<span style="color:blue">EN TRAMITE</span>' ); ?></td>
                            <td style="text-align: right"><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['EFECTIVO'] == 0 ? "&nbsp;" : ($r['EFECTIVO'] == NULL ? "&nbsp" : number_format(floatval($r["EFECTIVO"] + $r["TARJETA"]),2)))); ?></td>
                            <td style="text-align: right"><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['CHEQUE'] == 0 ? "&nbsp;" : ($ch['BANCO'] == "BI" ? number_format(floatval($r['CHEQUE']),2) : "&nbsp")));?></td>
                            <td style="text-align: right"><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['CHEQUE'] == 0 ? "&nbsp;" : ($ch['BANCO'] != "BI" ? number_format(floatval($r['CHEQUE']),2) : "&nbsp")));?></td>
                            <td style="text-align: right"><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['DEPOSITO'] == 0 ? "&nbsp;" : ($r['DEPOSITO'] == NULL ? "&nbsp" : number_format(floatval($r["DEPOSITO"]),2)))); ?></td>
                            <td style="text-align: right"><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r["NO_BOLETA"] == NULL ? "&nbsp;" : $r['NO_BOLETA'])); ?></td>
                            <td style="text-align: right"><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['DOLARES'] == 0 ? "&nbsp;" : ($r['DOLARES'] == NULL ? "&nbsp" : number_format(floatval($r["DOLARES"]),2))));?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $inscripcion > 0 ) ? number_format(floatval($inscripcion),2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $mesAtras > 0 ) ? number_format(floatval($mesAtras),2)."".$fechas : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $mesActual > 0 ) ? number_format(floatval($mesActual),2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $mesSiguiente > 0 ) ? number_format(floatval($mesSiguiente),2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $mora > 0)? number_format(floatval($mora),2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $libros > 0 ) ? number_format(floatval($libros),2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $diplo > 0 ) ? number_format(floatval($diplo),2 ) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $otros > 0 ) ? number_format(floatval($otros), 2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $chRecha > 0 ) ? number_format(floatval($chRecha), 2) : "&nbsp"; ?></td>
                            <td><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['CHEQUE'] > 0 ? $ch['BANCO'] : "&nbsp;"));?></td>
                            <td><?php echo ($stadoFactu == 0 ? "&nbsp" : ($r['CHEQUE'] > 0 ? $ch['NUMERO'] : "&nbsp;"));?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 ) ? number_format($r['TOTAL'],2) : "&nbsp"; ?></td>
                            <td align="right"><?php echo ($stadoFactu!=0 && $stadoFactu!=0 && $r['TASA_CAMBIO'] > 0 )?number_format(floatval($r['TASA_CAMBIO']),2) : "&nbsp"; ?></td>
                        </tr>
              <?php } 
                    ?>
                    <tr>
                        <td width="5%">&nbsp;</td>
                        <td width="4%">&nbsp;</td>
                        <td width="5%">&nbsp;</td>
                        <td width="7%"><strong>Totales</strong></td>
                        <td width="5%"><strong><?php print number_format(floatval($totalEfectivo), 2); ?></strong></td>
                        <td width="5%"><strong><?php print number_format(floatval($totalBI), 2); ?></strong></td>
                        <td width="6%"><strong><?php print number_format(floatval($totalOtrosBancos), 2); ?></strong></td>
                        <td width="6%"><strong><?php print number_format(floatval($totalDeposito), 2); ?></strong></td>
                        <td width="4%">&nbsp;</td>
                        <td width="5%"><strong><?php print number_format(floatval($totalDolares), 2); ?></strong></td>
                        <th width="3%"><?php print $totalInscripcion > 0 ? number_format(floatval($totalInscripcion), 2) : number_format(0, 2); ?></th>
                        <th width="3%"><?php print $totalMesAtras > 0 ? number_format(floatval($totalMesAtras), 2) : number_format(0, 2); ?></th>
                        <th width="3%"><?php print number_format(floatval($totalMesActual), 2); ?></th>
                        <th width="3%"><?php print number_format(floatval($totalMesSiguiente), 2); ?></th>
                        <td width="4%"><strong><?php print number_format(floatval($totalMora), 2); ?></strong></td>
                        <td width="4%"><strong><?php print number_format(floatval($totalLibros), 2); ?></strong></td>
                        <td width="8%"><strong><?php print number_format(floatval($totalDiplo), 2); ?></strong></td>
                        <td width="5%"><strong><?php print number_format(floatval($totalOtros), 2); ?></strong></td>
                        <td width="5%"><strong><?php print number_format(floatval($totalChRecha), 2); ?></strong></td>
                        <td width="5%"><strong>&nbsp;</strong></td>
                        <td width="5%"><strong>&nbsp;</strong></td>
                        <td width="7%"><strong><?php print number_format(floatval($totalFact), 2);?></strong></td>
                        <td width="5%">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="5%"><strong><?php echo $iFact; ?></strong></td>
                        <td width="4%">&nbsp;</td>
                        <td width="5%">&nbsp;</td>
                        <td width="7%"><strong>&nbsp;</strong></td>
                        <td width="5%"><strong><?php echo $iEfectivo; ?></strong></td>
                        <td width="5%"><strong><?php echo $iBI; ?></strong></td>
                        <td width="6%"><strong><?php echo $iOtrosBancos; ?></strong></td>
                        <td width="6%"><strong><?php echo $iDeposito; ?></strong></td>
                        <td width="4%">&nbsp;</td>
                        <td width="5%"><strong><?php echo $iDolares; ?></strong></td>
                        <td width="3%"><strong><?php echo $iInscripcion; ?></strong></td>
                        <td width="3%"><strong><?php echo $iMesAtras; ?></strong></td>
                        <td width="3%"><strong><?php echo $iMesActual; ?></strong></td>
                        <td width="3%"><strong><?php echo $iMesSiguiente; ?></strong></td>
                        <td width="4%"><strong><?php echo $iMora; ?></strong></td>
                        <td width="4%"><strong><?php echo $iLibros; ?></strong></td>
                        <td width="8%"><strong><?php echo $iDiplo; ?></strong></td>
                        <td width="5%"><strong><?php echo $iOtros; ?></strong></td>
                        <td width="5%"><strong><?php echo $iChRecha; ?></strong></td>
                        <td width="5%"><strong>&nbsp;</strong></td>
                        <td width="5%"><strong>&nbsp;</strong></td>
                        <td width="7%"><strong><?php echo $iFact;?></strong></td>
                        <td width="5%">&nbsp;</td>
                    </tr>
                </table>
            </div>
            <br />
            <div id="resumendiv">
                <table width="100%" border="0" id="resumen" style="font-size:8px" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="33%">
                            <table style="width:80%" class="table table-striped table-bordered" border="0" cellspacing="0">
                                <tr>
                                    <th colspan="2"><legend style="font-size: 8px;">RESUMEN GENERAL</legend></th>   
                                </tr>
                                <tr>
                                    <td>Total Efectivo</td>
                                    <td align="right">Q.<?php print number_format(floatval($totalEfectivo),2); ?></td>
                                </tr>
                                <tr>
                                    <td width="55%">Total Cheques BI</td>
                                    <td width="45%" align="right">Q.<?php print number_format(floatval($totalBI),2); ?></td>
                                </tr>
                                <tr>
                                    <td>Total Cheques Otros Bancos</td>
                                    <td align="right">Q.<?php print number_format(floatval($totalOtrosBancos),2); ?></td>
                                </tr>
                                <tr>
                                    <td>Total Depositos</td>
                                    <td align="right">Q.<?php print number_format(floatval($totalDeposito),2); ?></td>
                                </tr>
                                <tr class="tituloResumen">
                                    <td>Total Ingresos Quetzales</td>
                                    <td align="right">Q.
                                        <?php
                                        print number_format(floatval($totalQ),2);
                                        ?>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Total Ingresos Dolares</td>
                                    <td align="right">&#36;<?php print number_format(floatval($totalDolares),2); ?></td>
                                </tr>
                                <tr>
                                    <td width="55%">Dolares por Tipo de Cambio</td>
                                    <td align="right">Q.
                                        <?php
                                        $ingresoDol=$tipoCambio*$totalDolares;
                                        print number_format(floatval($ingresoDol),2);
                                        ?>
                                    </td>
                                </tr>
                                <tr class="tituloResumen">
                                    <td>Total Ingresos</td>
                                    <td align="right">Q.<?php print number_format(floatval($totalQ+$ingresoDol),2); ?></td>
                                </tr>
                                <tr class="tituloResumen">
                                    <td>Total en tramite</td>
                                    <td align="right">Q.<?php print number_format(floatval($totalTramite),2); ?></td>
                                </tr>
                                <tr class="tituloResumen">
                                    <td>Total Facturado</td>
                                    <td align="right">Q.<?php print number_format(floatval($totalFact),2); ?></td>
                                </tr>
                                <tr>
                                    <td>Diferencia</td>
                                    <td align="right">Q.<?php print number_format(floatval(($ingresoDol+$totalQ) - $totalFact),2); ?></td>
                                </tr>
  
                            </table>
                        </td>
                        <td width="33%" valign="top">
                            <table style="width:80%" class="table table-bordered table-striped" border="0" cellspacing="0">
                                <tr>
                                    <th colspan="2" class="noPad"><legend style="font-size: 8px">REPORTE DE FACTURACION</legend></th>
                                </tr>
                                <tr>
                                    <td class="noPad">Inscripcion</td>
                                    <td align="right" class="noPad">Q.<?php print number_format(floatval($totalInscripcion), 2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Mes ant.</td>
                                    <td class="noPad" align="right">Q.<?php print $totalMesAtras > 0 ? number_format(floatval($totalMesAtras), 2) : number_format(0, 2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Mes act.</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalMesActual), 2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Mes sig.</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalMesSiguiente),2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Mora</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalMora),2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Libros</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalLibros),2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Otros</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalOtros),2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad">Diplomados Externos</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalDiplo),2); ?></td>
                                </tr>
                                <tr>
                                    <td class="noPad" >Cargos Cheques Rech.</td>
                                    <td class="noPad" align="right">Q.<?php print number_format(floatval($totalChRecha),2); ?></td>
                                </tr>
                                <tr>
                                    <th class="noPad" >Total facturado del mes</th>
                                    <th class="noPad" align="right">Q.<?php print number_format(floatval($totalFact),2); ?></th>
                                </tr>
                            </table>
                        </td>
                        <td width="33%">
                             <table style="margin-left:10%;" border="0" cellspacing="0" cellpadding="0" width="80%">
      
                                <tr>
                                    <td><legend style="font-size:10px">Elaborado Por</legend></td>    
                                </tr>
                                
                                <tr>
                                    <td><legend style="font-size:10px">Revisado Por</legend></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>